package com.sand.mobilever;

import org.junit.Test;

import java.util.HashMap;
import java.util.Set;

public class SDKTestSendTemplateSMS {

	/**
	 * 获取手机验证码
	 */
	public static String sendMesModel(String phone){
		HashMap<String, Object> result = null;

		CCPRestSDK restAPI = new CCPRestSDK();
		restAPI.init("app.cloopen.com", "8883");// 初始化服务器地址和端口，格式如下，服务器地址不需要写https://
		restAPI.setAccount("8a216da87d55f9cc017d6ae382b9047f", "7f86e2359ec64f1aa1e80e75436a1c95");// 初始化主帐号和主帐号TOKEN
		restAPI.setAppId("8a216da87d55f9cc017d6ae383d20485");  // 初始化应用ID
		int mobile_code = (int)((Math.random()*9+1)*100000);		//用随机数当验证码
		String yzm = String.valueOf(mobile_code);  //接收验证码
		result = restAPI.sendTemplateSMS(phone,"1" ,new String[]{yzm,"1"});


		System.out.println("SDKTestSendTemplateSMS result=" + result);
		
		if("000000".equals(result.get("statusCode"))){
			//正常返回输出data包体信息（map）
			HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
			Set<String> keySet = data.keySet();
			for(String key:keySet){
				Object object = data.get(key);
				System.out.println(key +" = "+object);
			}
		}else{
			//异常返回输出错误码和错误信息
			System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
		}
		return yzm;
	}
}
